﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CWCS.Common.GeneralUtils
{
    public class ReadJsonHelper
    {
        public static string ReadJsonFile(string key)
        {
            string jsonfile = System.Environment.CurrentDirectory + "\\appsettings.json";//JSON文件路径

            using (System.IO.StreamReader file = System.IO.File.OpenText(jsonfile))
            {
                try
                {
                    using (JsonTextReader reader = new JsonTextReader(file))
                    {
                        JObject o = (JObject)JToken.ReadFrom(reader);

                        return o["WebSocket"][key].ToString();

                    }
                }
                catch
                {
                    return null;
                }
                finally
                {
                    file.Dispose();
                }
            }
        }
    }
}
